﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:p="clr-namespace:Lithnet.Acma.Presentation"
                    xmlns:a="clr-namespace:Lithnet.Acma;assembly=Lithnet.Acma"
                    xmlns:fim="clr-namespace:Microsoft.MetadirectoryServices;assembly=Microsoft.MetadirectoryServicesEx"
                    xmlns:core="clr-namespace:Lithnet.Common.Presentation;assembly=Lithnet.Common.Presentation"
                    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase">

    <DataTemplate  DataType="{x:Type p:AcmaSchemaAttributesViewModel}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid.Resources>
                <CollectionViewSource Source="{Binding Path=.,Mode=OneWay}"
                                      x:Key="sortedAttributes">
                    <CollectionViewSource.SortDescriptions>
                        <scm:SortDescription PropertyName="Name" />
                    </CollectionViewSource.SortDescriptions>
                </CollectionViewSource>

            </Grid.Resources>

            <ListView Grid.Row="0"
                      Margin="6"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                      ItemsSource="{Binding Source={StaticResource sortedAttributes}}"
                      Name="AttributesListView">
                <ListView.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Add attribute..."
                                  Command="{Binding Commands.AddAttribute}" />
                    </ContextMenu>
                </ListView.ContextMenu>
                <ListView.Resources>
                    <ContextMenu x:Key="ItemContextMenu">
                        <MenuItem Header="Add attribute..."
                                  Command="{Binding Commands.AddAttribute}" />
                        <MenuItem Header="Delete attribute..."
                                  Command="{Binding Commands.DeleteAttribute}" />
                    </ContextMenu>
                </ListView.Resources>
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="ContextMenu"
                                Value="{StaticResource ItemContextMenu}" />
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Name" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Source="{Binding Path=DisplayIcon}" />
                                        <TextBlock Text="{Binding Path=Name}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Type" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=TypeName}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Multivalued" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=IsMultivalued}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Indexed" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=IsIndexed}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Operation" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=Operation}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Bindings" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=Bindings}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Back-link target" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=BackLinks}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto">
                            <GridViewColumnHeader Content="Forward-link source" />
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=ForwardLinks}" />
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>

            <StackPanel Grid.Row="1">
                <Grid Margin="0 50 0 0"
                      DataContext="{Binding SelectedItem, ElementName=AttributesListView}">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Label Content="Name"
                           Grid.Row="0"
                           Grid.Column="0" />
                    <TextBox Text="{Binding Name, ValidatesOnDataErrors=True, ValidatesOnExceptions=true, Mode=TwoWay}"
                             Grid.Row="0"
                             Grid.Column="1"
                             Margin="2"
                             IsReadOnly="{Binding IsBuiltIn}" />

                    <Label Content="Data type"
                           Grid.Row="1"
                           Grid.Column="0" />
                    <TextBox Text="{Binding TypeName, ValidatesOnDataErrors=True, ValidatesOnExceptions=true, Mode=OneWay}"
                             Grid.Row="1"
                             Margin="2"
                             Grid.Column="1"
                             IsReadOnly="True" />

                    <CheckBox Content="Multivalued"
                              Grid.Row="2"
                              Grid.Column="1"
                              Margin="2"
                              VerticalAlignment="Center"
                              IsEnabled="False"
                              IsChecked="{Binding IsMultivalued, ValidatesOnDataErrors=True, ValidatesOnExceptions=true, Mode=OneWay}" />

                    <CheckBox Content="Indexable"
                              Grid.Row="3"
                              Grid.Column="1"
                              Margin="2"
                              VerticalAlignment="Center"
                              IsEnabled="False"
                              IsChecked="{Binding IsIndexable, ValidatesOnDataErrors=True, ValidatesOnExceptions=true, Mode=OneWay}" />

                    <CheckBox Content="Indexed"
                              Grid.Row="4"
                              Grid.Column="1"
                              Margin="2"
                              VerticalAlignment="Center"
                              IsEnabled="{Binding Path=CanChangeIndex, Mode=OneWay}"
                              IsChecked="{Binding Path=IsIndexed, ValidatesOnDataErrors=True, ValidatesOnExceptions=true, Mode=TwoWay}" />

                    <Label Content="Supported Operation"
                           Grid.Row="5"
                           Grid.Column="0" />
                    <ComboBox ItemsSource="{Binding Source={core:EnumExtension {x:Type a:AcmaAttributeOperation}}, Mode=OneWay}"
                              SelectedValue="{Binding Operation, ValidatesOnDataErrors=True, ValidatesOnExceptions=true}"
                              SelectedValuePath="Value"
                              IsEnabled="{Binding CanModify}"
                              Grid.Row="5"
                              Grid.Column="1" />

                    <Label Content="This is a built-in attribute and cannot be changed"
                           Grid.Row="6"
                           Grid.ColumnSpan="2"
                           Visibility="{Binding IsBuiltIn, Converter={StaticResource BooleanToVisibilityConverter}}" />

                </Grid>
            </StackPanel>

        </Grid>
    </DataTemplate>

</ResourceDictionary>